<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>党组织积分审批管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/layout.css">
	<script src="<%=request.getContextPath()%>/static/layer/layer.js"></script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/approve/partyApprove/">党组织积分审批列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="homeApprove" action="${ctx}/approve/partyApprove/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input type="hidden" name="ids" id="ids">
		<!-- 审批操作动态值 -->
		<input type="hidden" name="state" id="state"> 
		<ul class="ul-form">
			<li><label>活动名称：</label>
				<form:input path="lifename" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>所属支部：</label>
				<form:input path="organizationName" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li><label>状态：</label>
				<form:select path="shstate" class="input-medium" style="width:90px">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getLifeApproveStatus('2,3,4,5')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
			<li class="btns"><input id="agreeBtn" class="btn btn-primary" type="button" value="同意"/></li>
			<li class="btns"><input id="rejectBtn" class="btn btn-primary" type="button" value="拒绝"/></li>
			<li class="btns"><input id="backBtn" class="btn btn-primary" type="button" value="退回"/></li>
			<li class="btns"><input id="queryBtn" class="btn btn-primary" type="button" value="查看"/></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th width="5%" style='text-align:center'><input type="checkBox" id="checkAll"/></th>
				<th>活动名称</th>
				<th>积分内容</th>
				<th>所属支部</th>
				<th>审核状态</th>
				<th>活动时间</th>
				<th>申请积分</th>
				<shiro:hasPermission name="approve:partyApprove:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="homeApprove">
			<tr>
				<td style='text-align:center'>
					<input type="hidden" name="shstate" value='${homeApprove.shstate}'/>
					<input type='checkbox' name='ids' value='${homeApprove.id}'/>
				</td>
				<td>
					<a href="${ctx}/approve/partyApprove/form?id=${homeApprove.id}">${homeApprove.lifename}</a>
				</td>
				<td>
					${homeApprove.scoreContent}
				</td>
				<td>
					${homeApprove.organizationName}
				</td>
				<td style="text-align: center">
					${fns:getDictLabel(homeApprove.shstate, 'life_approve_status', '')}
				</td>
				<td style="text-align: center">
					<fmt:formatDate value="${homeApprove.starttime}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td style="text-align: center">
					${homeApprove.applyScore}
				</td>
				<shiro:hasPermission name="approve:partyApprove:edit"><td>
    				<a href="${ctx}/approve/partyApprove/form?id=${homeApprove.id}">修改</a>
					<a href="${ctx}/approve/partyApprove/delete?id=${homeApprove.id}" onclick="return confirmx('确认要删除该党组织积分审批吗？', this.href)">删除</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	<script type="text/javascript">
		$(document).ready(function() {
			getCheckList=function(){
				var ids = [];
					$("input[name='ids']:checked").each(function(){
						ids.push($(this).val());
					});
				return ids;
			}
			$("#checkAll").on('click', function() {
				var ch = this.checked;  //复选框
				if(ch){
					$("input[name='ids']").prop("checked", true);
				}else{
					$("input[name='ids']").prop("checked", false);
				}
			});
			

			valdateState = function(state){
				var flag = true;
				var state = '2';//待审核
				$("input[name='ids']:checked").each(function(){
					if(state != $(this).prev().val()){
						flag = false;
						return false;
					}
				});
				return flag;
			}
			
			//同意按钮事件
			$("#agreeBtn").on('click', function() {
				var flag = valdateState();
				if(!flag){
					$.jBox.alert("请选择待审核记录进行操作","提示");
					return false;
				}
				var ids =getCheckList();
				if(ids.length<1){
					$.jBox.alert("请选择至少一条记录进行同意操作","提示");
					return false;
				}
				
				$("#ids").val(ids);
				
				$.ajax({
					url:'${ctx}/approve/activityApprove/checkScoreTotal?ids='+ids,
					type:'post',
					dataType:"json",
					success:function(data){
						var code = data.code;
						var lifeName = data.lifeName;
						if(code == "200"){
							top.$.jBox.confirm("确认要同意勾选的记录吗？","提示",function(v,h,f){
								if(v=="ok"){
									$("#searchForm").attr("action","${ctx}/approve/partyApprove/batchAgreeOrganizeLife");
									$("#searchForm").submit();
								}
							},{buttonsFocus:1});
							top.$('.jbox-body .jbox-icon').css('top','55px');
						}else{
							layer.msg(lifeName+"活动积分超过上限");
							return false;
						}
					}
				});
			});
			
			//拒绝按钮事件
			$("#rejectBtn").on('click', function() {
				var flag = valdateState();
				if(!flag){
					$.jBox.alert("请选择待审核记录进行操作","提示");
					return false;
				}
				var ids =getCheckList();
				if(ids.length<1){
					$.jBox.alert("请选择至少一条记录进行拒绝操作","提示");
					return false;
				}
				top.$.jBox.confirm("确认要拒绝勾选的记录吗？","提示",function(v,h,f){
					$("#ids").val(ids);
					$("#state").val('4');
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/approve/partyApprove/batchUpdateOrganizeLifeStatus");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			
			//撤回按钮事件
			$("#backBtn").on('click', function() {
				var flag = valdateState();
				if(!flag){
					$.jBox.alert("请选择待审核记录进行操作","提示");
					return false;
				}
				var ids =getCheckList();
				if(ids.length<1){
					$.jBox.alert("请选择至少一条记录进行退回操作","提示");
					return false;
				}
				top.$.jBox.confirm("确认退回勾选的记录吗？","提示",function(v,h,f){
					$("#ids").val(ids);
					$("#state").val('5');
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/approve/partyApprove/batchUpdateOrganizeLifeStatus");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			
			$("#queryBtn").on('click', function() {
				var ids =getCheckList();
				if(ids.length!=1){
					$.jBox.alert("请选择一条记录进行查看",'提示');
					return false;
				}
				window.location.href="${ctx}/approve/partyApprove/form?id="+ids[0].split('|')[0];
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</body>
</html>